package com.xjtu.chapter08.thread.linkedblockingqueue;

import java.util.concurrent.BlockingQueue;

/**
 * @author yjq
 * @version 1.0
 * @date 2021/9/1 10:45
 */
public class Consumer implements Runnable {
    BlockingQueue<Product> queue;

    public Consumer(BlockingQueue<Product> queue) {
        this.queue = queue;
    }

    @Override
    public void run() {
        try{
            Product temp = queue.take();//取出产品，如果队列为空，会阻塞当前线程
            System.out.println("I took out "+temp);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
